﻿using RemoteTestRunner.Contracts;

namespace RemoteTestRunner.BusinessLogic
{
    /// <summary>
    ///   Specifies the type of service object to be used.
    /// </summary>
    public enum ServiceType
    {
        /// <summary>
        ///   Specifies a client-side service will be used.
        /// </summary>
        ClientService,

        /// <summary>
        ///   Specifies a server-side service will be used.
        /// </summary>
        ServerService
    }

    public static class ServiceFactory
    {
        static ServiceFactory()
        {
            IoC.Container.RegisterType<IRtrService, RtrLib>("local");
            //IoC.Container.RegisterType<RTRService.IRTRService, ServerFacade>("remote");
        }

        /// <summary>
        ///   Gets the appropriate service object based on the requested type.
        /// </summary>
        /// <param name = "serviceType">Type of the service object to be created.</param>
        /// <returns>An instance of <see cref = "IRtrService" /> for the requested
        ///   service type.</returns>
        public static IRtrService GetServiceObject(ServiceType serviceType)
        {
            switch (serviceType)
            {
                case ServiceType.ClientService:
                    return IoC.Container.Resolve<IRtrService>("local");
                //return new RtrLib();
                case ServiceType.ServerService:
                    return IoC.Container.Resolve<IRtrService>("remote");
                //return new ServerFacade();
                default:
                    return null;
            }
        }

        /// <summary>
        ///   Gets the appropriate service object based on the requested type.
        /// </summary>
        /// <param name = "serviceUrl">The URL of the WCF service being utilized.</param>
        /// <param name = "timeoutSeconds">The timeout seconds.</param>
        /// <returns>
        ///   An instance of <see cref = "IRtrService" /> for the requested
        ///   service type.
        /// </returns>
        public static IRtrService GetServiceObject(string serviceUrl, int timeoutSeconds)
        {
            return new ServerFacade(serviceUrl, timeoutSeconds);
        }
    }
}